﻿Public Class TurnosMedicos

    Public Property _dniPersona As String
    Public Property _fechahorarioturno As String
    Public Property _Especialidad As String
    Public Property _dnimedico As String
    Public Property _id_institucion As String

    Property dniPersona() As String
        Get
            Return _dniPersona
        End Get
        Set(value As String)
            _dniPersona = value
        End Set
    End Property

    Property fechahorarioturno() As String
        Get
            Return _fechahorarioturno
        End Get
        Set(value As String)
            _fechahorarioturno = value
        End Set
    End Property

    Property Especialidad() As String
        Get
            Return _Especialidad
        End Get
        Set(value As String)
            _Especialidad = value
        End Set
    End Property

    Property dnimedico() As String
        Get
            Return _dnimedico
        End Get
        Set(value As String)
            _dnimedico = value
        End Set
    end property

    Property id_institucion() As String
        Get
            Return _id_institucion
        End Get
        Set(value As String)
            _id_institucion = value
        End Set
    End Property

End Class

Public Class Persona

    'variables publicas
    Dim NOmbre As String
    Dim Apellido As String
    Dim Dni As String
    Dim FechaNac As Date
    Dim Perfil() As String
    Dim Nivel_perfil() As String
    Dim Usuario As String
    Dim PassWord As String
    Dim Anio_EN_Meses As Integer
    Dim Anio As Integer
    Dim SeDebeReceteoDeCuenta As Boolean
    Dim Sexo As String
    Dim DniProvisorio As Boolean
    Dim Madre As String
    Dim Padre As String
    Dim Mail As String
    Dim Nacionalidad As String
    Dim NivelPerfil As Integer
    Dim GRupo_Sanguinio As String
    Dim ID_Institucion As Integer
    Dim Institucion As String
    Dim Telefono As String
    Dim celular As String

    Dim Direccion As String
    Dim numeroDireccion As String
    Dim Cod_postal As String
    Dim Localidad As String

    Dim Huella As String

    Dim Especialidades() As String

    Dim PedidoCaptura As Boolean
    Dim FechaCaptura As String

    Dim EstaInternado As Boolean

    Dim EstaMuerto As Boolean







    'id-de tablas 
    Dim ID_persona As Integer
    Dim Id_Usuario As Integer
    '----------------------------

    'propiedades
    Public Property Dev_ApellidoYnombre() As String
    Public Property Dev_usuario() As String
    Public Property Dev_ExistePersona As Boolean
    Public Property Dev_ResetearClave As Boolean
    Public Property Dev_Edad As Integer
    Public Property Dev_Edad_en_meses As Integer
    Public Property Dev_FechaNacimiento As Date
    Public Property Dev_Dni As String
    Public Property Dev_sexo As String
    Public Property Dev_TieneDniProvisorio As Boolean
    Public Property Dev_madre As String
    Public Property Dev_padre As String
    Public Property Dev_mail As String
    Public Property Dev_nacionalidad As String
    Public Property Dev_contraseña As String
    Public Property dev_perfilUsuario As String
    Public Property Dev_Grupo_sanguinio As String
    Public Property Dev_ID_Institucion As Integer
    Public Property Dev_INstitucionDeTrabajo As String
    Public Property Dev_telefono As String
    Public Property Dev_celular As String
    Public Property Dev_Direccion As String
    Public Property Dev_numeroDireccion As String
    Public Property Dev_CodPostal As String
    Public Property Dev_Localidad As String
    Public Property Dev_hueLLa As String
    Public Property Dev_PedidoCaptura As Boolean
    Public Property dev_fechaPEdidoCaptura As String
    Public Property Dev_Nombre As String
    Public Property Dev_apellido As String
    Public Property Dev_EsMedico As Boolean
    Public Property Dev_EstaInternado As Boolean
    Public Property Dev_EstaMurido As Boolean














    Public Sub Set_Perfil(ByVal perfil As String)

        dev_perfilUsuario = perfil

    End Sub

    Public Function Dev_NivelDepefi(ByVal El_perfil As String) As Integer
        Dim i As Integer


        For i = LBound(Perfil) To UBound(Perfil)
            If UCase(Perfil(i)) = UCase(El_perfil) Then
                Dev_NivelDepefi = CInt(Nivel_perfil(i))
                Exit Function
            End If
        Next i

        Dev_NivelDepefi = 0


    End Function

    Public Function dev_PerfilId() As Integer
        dev_PerfilId = Dev_NivelDepefi(Perfil(0))
    End Function

    Public Sub CargaComboCnPeril(ByRef Combo As DropDownList, Optional ByVal lblEtiqueta As Label = Nothing)
        Dim I As Single


        'vacio el combo
        Combo.Items.Clear()
        '---------------------

        For I = LBound(Perfil) To UBound(Perfil)
            Combo.Items.Add(Perfil(I))
        Next I

        If Combo.Items.Count = 1 And UCase(Combo.Text) = UCase("Paciente Web") Then
            Combo.Visible = False
            If IsNothing(lblEtiqueta) = False Then
                lblEtiqueta.Visible = False
            End If


        Else
            Combo.Visible = True
            If IsNothing(lblEtiqueta) = False Then
                lblEtiqueta.Visible = True
            End If

        End If



    End Sub

    Private Sub CargaVariables(ByVal Rs As ADODB.Recordset)


        If Rs.RecordCount = 0 Then

            Me.NOmbre = ""
            Me.Apellido = ""
            Me.Dni = ""
            Me.FechaNac = Date.Now
            Me.Usuario = ""
            Me.PassWord = ""
            Me.Anio_EN_Meses = 0
            Me.Anio = 0
            Me.ID_persona = 0
            Me.Id_Usuario = 0
            Me.SeDebeReceteoDeCuenta = False

            Me.Sexo = ""
            Me.DniProvisorio = False
            Me.Madre = ""
            Me.Padre = ""
            Me.Mail = ""
            Me.GRupo_Sanguinio = ""
            Me.ID_Institucion = 0
            Me.Institucion = ""
            Me.Telefono = ""
            Me.celular = ""
            Me.Direccion = ""
            Me.numeroDireccion = ""
            Me.Cod_postal = ""
            Me.Localidad = ""
            Me.Huella = ""
            Me.PedidoCaptura = False
            Me.FechaCaptura = ""

            Me.EstaInternado = False

            Me.EstaMuerto = False

            'propiedad
            Dev_ExistePersona = False

            Exit Sub


        End If



        'le cargo las variables 

        Me.NOmbre = Rs.Fields(0).Value.ToString
        Me.Apellido = Rs.Fields(1).Value.ToString
        Me.Dni = Rs.Fields(2).Value.ToString
        Me.FechaNac = CDate(Rs.Fields(3).Value.ToString)
        Me.Usuario = Rs.Fields(4).Value.ToString
        Me.PassWord = Rs.Fields(5).Value.ToString
        Me.ID_persona = CInt(Rs.Fields(6).Value.ToString)
        Me.Id_Usuario = CInt(Rs.Fields(7).Value.ToString)
        Me.SeDebeReceteoDeCuenta = CBool(Rs.Fields(8).Value.ToString)
        Me.Anio = CInt(Rs.Fields(9).Value.ToString)
        Me.Anio_EN_Meses = CInt(Rs.Fields(10).Value.ToString)

        Me.Sexo = Rs.Fields(11).Value.ToString
        Me.DniProvisorio = CBool(Rs.Fields(12).Value.ToString)
        Me.Madre = Rs.Fields(13).Value.ToString
        Me.Padre = Rs.Fields(14).Value.ToString
        Me.Mail = Rs.Fields(15).Value.ToString
        Me.Nacionalidad = Rs.Fields(16).Value.ToString
        Me.GRupo_Sanguinio = Rs.Fields(17).Value.ToString

        Me.ID_Institucion = CInt(Rs.Fields(18).Value.ToString)
        Me.Institucion = Rs.Fields(19).Value.ToString

        Me.Telefono = Rs.Fields(20).Value.ToString
        Me.celular = Rs.Fields(21).Value.ToString

        Me.Direccion = Rs.Fields(22).Value.ToString
        Me.numeroDireccion = Rs.Fields(23).Value.ToString
        Me.Cod_postal = Rs.Fields(24).Value.ToString
        Me.Localidad = Rs.Fields(25).Value.ToString

        Me.Huella = Rs.Fields(26).Value.ToString

        Me.PedidoCaptura = CBool(Rs.Fields(27).Value)
        Me.FechaCaptura = Rs.Fields(28).Value.ToString

        Me.EstaInternado = CBool(Rs.Fields(29).Value)

        Me.EstaMuerto = CBool(Rs.Fields(30).Value)

        'cargo las propiedades para despues devolver el valor 
        '------------------------------------------------------
        Dev_ApellidoYnombre = Me.Apellido & ", " & Me.NOmbre

        Dev_ExistePersona = True

        Dev_ResetearClave = Me.SeDebeReceteoDeCuenta

        Dev_Edad = CInt(Me.Anio)

        Dev_Edad_en_meses = CInt(Me.Anio_EN_Meses)

        Dev_Dni = Me.Dni

        Dev_FechaNacimiento = Me.FechaNac

        Dev_sexo = Me.Sexo

        Dev_TieneDniProvisorio = Me.DniProvisorio

        Dev_madre = Me.Madre

        Dev_padre = Me.Padre

        Dev_mail = Me.Mail

        Dev_nacionalidad = Me.Nacionalidad

        Dev_Grupo_sanguinio = Me.GRupo_Sanguinio

        Dev_usuario = Me.Usuario

        Dev_contraseña = Me.PassWord

        Dev_ID_Institucion = Me.ID_Institucion

        Dev_INstitucionDeTrabajo = Me.Institucion

        Dev_telefono = Me.Telefono
        Dev_celular = Me.celular

        Dev_Direccion = Me.Direccion
        Dev_numeroDireccion = Me.numeroDireccion
        Dev_CodPostal = Me.Cod_postal
        Dev_Localidad = Me.Localidad

        Dev_hueLLa = Me.Huella


        Dev_PedidoCaptura = Me.PedidoCaptura
        dev_fechaPEdidoCaptura = Me.FechaCaptura


        Dev_apellido = Me.Apellido
        Dev_Nombre = Me.NOmbre

        Dev_EstaInternado = Me.EstaInternado

        Dev_EstaMurido = Me.EstaMuerto


        'Funcion que carga el perfil del usuario'
        cargaPerfiles(Me.Id_Usuario)
        Set_Perfil(Perfil(0))

        ''funcion que carga las especialidades 
        cargaEspecialiedades(Me.Dni)

    End Sub
    Private Sub cargaPerfiles(id_usuario As Integer)
        Dim Rs As ADODB.Recordset
        Dim Param(0) As ADODB.Parameter
        Dim I As Integer


        Param(0) = New ADODB.Parameter
        Param(0).Name = "@id_usuario"
        Param(0).Type = ADODB.DataTypeEnum.adInteger
        Param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        Param(0).Value = id_usuario  '
        '  param(0).Size = 10


        Rs = Datos.TraerTodos("TraePerfilesYnivelesDeUnaPersona", Param, "cargaPerfil - clasePersona")


        'inicializo los vectores 
        ReDim Perfil(0)
        ReDim Nivel_perfil(0)
        Perfil(0) = ""
        Nivel_perfil(0) = ""
        '-----------------------


        Rs.MoveFirst()

        'seto la propiedad de saber si es medico
        Dev_EsMedico = False
        '----------------------------------

        For I = 1 To Rs.RecordCount
            'redimensiono el vector 
            If Perfil(0) <> "" Then
                ReDim Preserve Perfil(UBound(Perfil) + 1)
                ReDim Preserve Nivel_perfil(UBound(Nivel_perfil) + 1)
            End If

            '-- ///esto es para saber si es medico//
            'me fijo si es medico'
            If UCase(Rs.Fields(0).Value.ToString) = UCase("medico") Then
                Dev_EsMedico = True
            End If
            '---------------------------------------

            Dev_EsMedico = True
            'cargo el vector ''

            Perfil(I - 1) = Rs.Fields(0).Value
            Nivel_perfil(I - 1) = Rs.Fields(1).Value.ToString

            Rs.MoveNext()
        Next I





    End Sub
    Public Sub SetaDatosXDn(Dni As String)
        Dim Rs As ADODB.Recordset
        Dim Param(0) As ADODB.Parameter


        Param(0) = New ADODB.Parameter
        Param(0).Name = "@dni"
        Param(0).Type = ADODB.DataTypeEnum.adVarChar
        Param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        Param(0).Value = Dni   '
        Param(0).Size = 10





        Rs = Datos.TraerTodos("traeDatosDeUnapersonaXdni", Param, "Modulo de clase persona -seteaDatosxDni")

        CargaVariables(Rs)





    End Sub

    Public Sub SetaDatosXUsuarioYContrasenia(Usuario As String, Pasword As String)

        Dim Rs As ADODB.Recordset
        Dim Param(1) As ADODB.Parameter


        Param(0) = New ADODB.Parameter
        Param(0).Name = "@Usuario "
        Param(0).Type = ADODB.DataTypeEnum.adVarChar
        Param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
        Param(0).Value = Usuario   '
        Param(0).Size = 50

        Param(1) = New ADODB.Parameter
        Param(1).Name = "@pasword "
        Param(1).Type = ADODB.DataTypeEnum.adVarChar
        Param(1).Direction = ADODB.ParameterDirectionEnum.adParamInput
        Param(1).Value = Pasword   '
        Param(1).Size = 50





        Rs = Datos.TraerTodos("traeDatosDeUnapersonaXUsuarioYPasword", Param, "Modulo de clase persona -seteaDatosxDni")

        CargaVariables(Rs)





    End Sub
    Public Sub CargaCombo_Cn_Especialidades(Combo As DropDownList)
        Dim I As Integer

        'vacio el combo''
        Combo.Items.Clear()
        '-----------


        ' el indice 0 no esta vacio es que hay datos 
        If Especialidades(0) <> "" Then
            For I = LBound(Especialidades) To UBound(Especialidades)
                Combo.Items.Add(Especialidades(I))
            Next I
        End If
        '   ---------------------------------



    End Sub
    Private Sub cargaEspecialiedades(_Dni As String)
        Dim Rs As ADODB.Recordset
        Dim Param(0) As ADODB.Parameter
        Dim i As Integer

        'redimensiono vector 
        ReDim Especialidades(0)
        'seteo
        Especialidades(0) = ""
        '--------------------------

        If _Dni <> "" Then
            '---busco el dato------
            Param(0) = New ADODB.Parameter
            Param(0).Name = "@Dni"
            Param(0).Type = ADODB.DataTypeEnum.adVarChar
            Param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
            Param(0).Value = _Dni   '
            Param(0).Size = 10

            Rs = Datos.TraerTodos("buscaEspecialidadXDni", Param, "clase persrona - Private Sub cargaEspecialiedades")



            If Rs.RecordCount > 0 Then
                Rs.MoveFirst()

                For i = 1 To Rs.RecordCount
                    If Especialidades(0) = "" Then
                        Especialidades(0) = Rs.Fields(0).Value.ToString
                    Else

                        ReDim Preserve Especialidades(UBound(Especialidades) + 1)
                        Especialidades(UBound(Especialidades)) = Rs.Fields(0).Value.ToString

                    End If


                    Rs.MoveNext()
                Next i
            End If

        End If



    End Sub
    Public Sub CargaComo_conVAcunasPendientes(Combo As DropDownList)
        Dim Rs As ADODB.Recordset
        Dim Param(0) As ADODB.Parameter

        'vacio el combo
        Combo.Items.Clear()
        '''''''''''''''


        If Me.Dni <> "" Then
            '---busco el dato------
            Param(0) = New ADODB.Parameter
            Param(0).Name = "@Dni"
            Param(0).Type = ADODB.DataTypeEnum.adVarChar
            Param(0).Direction = ADODB.ParameterDirectionEnum.adParamInput
            Param(0).Value = Me.Dni   '
            Param(0).Size = 10


            Rs = Datos.TraerTodos("TraeVacunasPendientesDeunaPersonaXdni", Param, "clase persrona - CargaComo_conVAcunasPendientes")

            If Rs.RecordCount > 0 Then
                Rs.MoveFirst()

                For I = 1 To Rs.RecordCount
                    Combo.Items.Add(Rs.Fields(0).Value.ToString)
                    Rs.MoveNext()
                Next I
            End If
        End If


    End Sub
End Class
